package com.lavender.async._async_response;

import com.lavender.async._common.ApiResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

/**
 * <p>
 * Callable异步响应
 * 使用场景：几乎不使用，功能太简单，没办法处理例如超时等异常。
 * 实现原理：Spring会将Callable交给TaskExecutor处理，TaskExecutor继承自java.util.concurrent.Executor。
 * </p>
 *
 * @author: zhu.chen
 * @date: 2021/3/23
 * @version: v1.0.0
 */
@RestController
@RequestMapping("/callable")
public class CallableResponse {

    /**
     * http://localhost:8086/async/callable/hello
     */
    @GetMapping("hello")
    public Callable<ApiResponse> hello(){
        return () -> {
            return ApiResponse.instanceSuccessApiResponse("hello world.");
        };
    }

}
